package com.ruoyi.video.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.video.server.nvr.NvrTestThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.video.mapper.VideoNvrMapper;
import com.ruoyi.video.domain.VideoNvr;
import com.ruoyi.video.service.IVideoNvrService;

/**
 * NVRService业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-09
 */
@Service
public class VideoNvrServiceImpl implements IVideoNvrService 
{
    @Autowired
    private VideoNvrMapper videoNvrMapper;

    /**
     * 查询NVR
     * 
     * @param id NVR主键
     * @return NVR
     */
    @Override
    public VideoNvr selectVideoNvrById(Long id)
    {
        return videoNvrMapper.selectVideoNvrById(id);
    }

    /**
     * 查询NVR列表
     * 
     * @param videoNvr NVR
     * @return NVR
     */
    @Override
    public List<VideoNvr> selectVideoNvrList(VideoNvr videoNvr)
    {
        return videoNvrMapper.selectVideoNvrList(videoNvr);
    }

    /**
     * 新增NVR
     * 
     * @param videoNvr NVR
     * @return 结果
     */
    @Override
    public int insertVideoNvr(VideoNvr videoNvr)
    {
        videoNvr.setCreateTime(new Date());
        int ret = videoNvrMapper.insertVideoNvr(videoNvr);
        new Thread(()->{
            NvrTestThread tester = new NvrTestThread();
            tester.init();
            tester.testNVR(videoNvr);
        }).start();
        return ret;
    }

    /**
     * 修改NVR
     * 
     * @param videoNvr NVR
     * @return 结果
     */
    @Override
    public int updateVideoNvr(VideoNvr videoNvr)
    {
        videoNvr.setUpdateTime(new Date());
        int ret = videoNvrMapper.updateVideoNvr(videoNvr);

        new Thread(()->{
            NvrTestThread tester = new NvrTestThread();
            tester.init();
            tester.testNVR(videoNvr);
        }).start();
        return ret;
    }

    /**
     * 批量删除NVR
     * 
     * @param ids 需要删除的NVR主键
     * @return 结果
     */
    @Override
    public int deleteVideoNvrByIds(Long[] ids)
    {
        return videoNvrMapper.deleteVideoNvrByIds(ids);
    }

    /**
     * 删除NVR信息
     * 
     * @param id NVR主键
     * @return 结果
     */
    @Override
    public int deleteVideoNvrById(Long id)
    {
        return videoNvrMapper.deleteVideoNvrById(id);
    }
}
